package sjtu.ist.warehouse4ws.service;

import java.util.List;

import sjtu.ist.warehouse4ws.dao.PermissionresourcesDao;
import sjtu.ist.warehouse4ws.dao.cust.CustPermissionresourcesDao;
import sjtu.ist.warehouse4ws.model.CustPermissionresources;
import sjtu.ist.warehouse4ws.model.Permissionresources;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;


public class PermissionresourcesServiceImpl implements PermissionresourcesService{
    private PermissionresourcesDao permissionresourcesDao;
    private CustPermissionresourcesDao custPermissionresourcesDao;
	
	public void setPermissionresourcesDao(
			PermissionresourcesDao permissionresourcesDao) {
		this.permissionresourcesDao = permissionresourcesDao;
	}


	public void setCustPermissionresourcesDao(
			CustPermissionresourcesDao custPermissionresourcesDao) {
		this.custPermissionresourcesDao = custPermissionresourcesDao;
	}


	@Override
	public Integer addPermissionresources(Permissionresources permissionresources,int companyId) {
		// TODO Auto-generated method stub
		if(companyId==Constants.ADMIN_COMPANY_ID){
			return permissionresourcesDao.save(permissionresources);
		}else{
			CustPermissionresources cp=new CustPermissionresources();
			PropertyHelper.copyProperties(permissionresources, cp);
			return custPermissionresourcesDao.save(cp);
		}
	}


	@Override
	public List getPermissionresourcesById(String id) {
		// TODO Auto-generated method stub
		return (List<Permissionresources>)permissionresourcesDao.findById(id);
	}
	
	@Override
	public List<String> getResourcesByPermissionid(String id) {
		// TODO Auto-generated method stub
		List<String> list=(List<String>)permissionresourcesDao.findResourcesByPermissionid(id);
		return (List<String>)permissionresourcesDao.findResourcesByPermissionid(id);
		
	}

}
